package com.javatest2;

import edu.princeton.cs.algs4.Point2D;
import sun.security.tools.policytool.PolicyTool;

/**
 * @author LL
 * 编写一个 Point2D 的用例，从命令行接受一个整数 N。在单位正方形中生成 N 个随机点，然后计
 * 算两点之间的最近距离
 * @create 2021-01-14 15:41
 */
public class Subject3 {

    public static void genePoint(Point2D[] a){
        for (int i = 0; i < a.length; i++) {
            a[i] = new Point2D(Math.random(),Math.random());//随机生成一个点
            a[i].draw();
        }
    }

    public static double distance(Point2D[] a){
        double min = 0;
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = i+1; j < a.length; j++) {
                double b = a[i].distanceTo(a[j]);
//                min = (min<b)?min:b;
                min = (min<b)?b:min;
            }
        }
        return min;
    }

    public static void main(String[] args) {
        String[] a = {"5"};
        int n = Integer.parseInt(a[0]);
        Point2D[] p = new Point2D[n];
        genePoint(p);
        System.out.println(distance(p));
    }
}
